package com.aboverock.module.system.service.impl;

import com.aboverock.module.system.domain.Department;
import com.aboverock.module.system.mapper.DepartmentMapper;
import com.aboverock.module.system.service.DepartmentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

// import com.aboverock.datalake.enums.DatalakeDataTypeEnum;
// import com.aboverock.datalake.exceptions.DatalakeDataParseException;
// import com.aboverock.datalake.exceptions.DatalakeRequestException;
// import com.aboverock.module.datalake.service.DatalakeService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Rock Wang
 * @since 2018-05-11
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {

    // @Autowired
    // private DatalakeService datalakeService;

    @Override
    public Department selectByDeptNo(String deptNo) {
        return this.getOne(new QueryWrapper<Department>().eq("dept_no", deptNo));
    }

    // @Override
    // public void updateDeptsFromDatalake() throws DatalakeRequestException, DatalakeDataParseException {
    //     Department latestUpdateDept = this.getOne(new QueryWrapper<Department>().orderByDesc("update_time").last(
    //             "limit 1"));
    //     if (null == latestUpdateDept) {
    //         List<Department> depts = datalakeService.getAllDepartments();
    //         depts.forEach(dept -> this.save(dept));
    //     } else {
    //         Map<DatalakeDataTypeEnum, List<Department>> depts = datalakeService
    //                 .listDepartmentsByGreatEqualUpdateTime(latestUpdateDept.getUpdateTime());
    //         depts.get(DatalakeDataTypeEnum.CREATE).forEach(dept -> this.save(dept));
    //         depts.get(DatalakeDataTypeEnum.UPDATE).forEach(
    //                 dept -> this.update(dept, new UpdateWrapper<Department>().eq("dept_no", dept.getDeptNo())));
    //         depts.get(DatalakeDataTypeEnum.DELETE).forEach(
    //                 dept -> this.remove(new QueryWrapper<Department>().eq("dept_no", dept.getDeptNo())));
    //     }
    // }

}
